<?php

namespace App\Http\Controllers\Admin\User;

use App\Http\Requests\PasswordRequest;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;

class Revise extends Controller
{
    public function __construct(){
        $this->middleware('checklogin');
    }

    public function index(){
        return view('admin.user.revise');
    }

    public function revises(Request $request,PasswordRequest $passwordRequest){
        //获得post数据
        $post = $request->all();
        //dd($post);
        //获得当前用户的旧数据
        $user = Auth::user();
        //dd($user);
        //当前username等于数据库的username
        $user->username = $post['username'];
        //判断密码是否填写，如果填写，就修改密码
        if ($post['password']){
            $user->password=bcrypt($post['password']);
        }
        //将数据用户保存
        $user->save();
        //设置闪存信息，并返回
        session()->flash('success','资料修改成功');
        //返回首页
        return redirect('/');
    }
}
